import 'package:flutter/material.dart';

/// 显示一个价格标签
class TagPrice extends StatelessWidget {
  final double price;
  final double? marketPrice;
  final Color color;
  final double fontSize;
  final bool lineThrough;

  const TagPrice(
    this.price, {
    Key? key,
    this.marketPrice,
    this.color = Colors.red,
    this.fontSize = 16,
    this.lineThrough = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.end,
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        Text(
          '￥',
          style: TextStyle(color: color, fontSize: fontSize - 4),
        ),
        Text(
          price.toStringAsFixed(2),
          style: TextStyle(fontSize: fontSize, color: color),
        ),
        if (marketPrice != null)
          Padding(
            padding: const EdgeInsets.only(left: 8.0),
            child: Text(
              "市场价：${price.toStringAsFixed(2)}",
              style: TextStyle(
                fontSize: fontSize - 2,
                color: Colors.grey,
                decoration: TextDecoration.lineThrough,
              ),
            ),
          ),
      ],
    );
  }
}
